package com.an.practise;

import com.an.utils.SumTool;

import java.util.Random;

/**
 * @author Li
 * @Date 2023/4/10 14:30
 */
public class ReversalArrayTest {
    public static void main(String[] args) {
        /**
         * 创建一个数组
         * 将数组进行反转
         */
        int[] array1 = getArray(5);
        int[] array2 = new int[array1.length];
        printArray(array1);
        array1 = RevesalArray(array1,array2);
        printArray(array1);
    }

    /**
     * 进行数组反转
     * @param array1
     * @param array2
     * @return
     */
    private static int[] RevesalArray(int[] array1,int[] array2) {
        for (int i = 0; i <array1.length/2 ; i++) {
            int temp = array1[i];
            array1[i] = array1[array1.length-i-1];
            array1[array1.length-i-1] = temp;
        }
        return array1;
    }

    /**
     * 打印数组
     */
    private static void printArray(int[] array) {
        System.out.print("[");
        for (int i = 0; i < array.length; i++) {
            if (i==array.length-1){
                System.out.println(array[i]+"]");
            }else {
                System.out.print(array[i]+",");
            }
        }
    }

    /**
     * 创建数组
     * @return
     */
    private static int[] getArray(int size) {
       int[] array = new int[size];
        Random random = new Random();
        for (int i = 0; i <array.length ; i++) {
            array[i] = random.nextInt(10);

        }
        return array;
    }

}
